<template>
    <div class="classify">
        <div class="left">
            <li v-for="(item,index) in data" :key="index" :class="index === currIndex ? 'active' : ''"
            @click="tab(index)">
                {{item.name}}
            </li>
        </div>
        <div class="right">
            <div v-if="data[currIndex]" class="box">
                <div class="head">
                    <h4>{{data[currIndex].name}}</h4>
                    <img :src="data[currIndex].img" alt="">
                </div>
                <div class="main">
                    <dl v-for="item in data[currIndex].children" :key="item.id">
                        <dt>
                            <img :src="item.img" alt="">
                        </dt>
                        <dd>
                            <h4>{{item.name}}</h4>
                            <p>{{item.title}}</p>
                            <span>￥{{item.price}}</span>
                        </dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            data:[],
            currIndex:0
        }
    },
    created() {
        axios.get('/list').then(res=>{
            this.data = res.data
        })
    },
    methods: {
        tab(index){
            this.currIndex = index
        }
    },
}
</script>

<style lang="scss" scoped>
.classify{
    width: 100%;
    height: 100%;
    display: flex;
    .left{
        flex: 1;
        border-right: 1px solid #ccc;
        li{
            width: 100%;
            height: 50px;
            text-align: center;
            border-bottom: 1px solid #ccc;
            line-height: 50px;
        }
    }
    .right{
        flex: 3;
        .box{
            width: 100%;
            height: 100%;
            overflow: auto;
            display: flex;
            flex-direction: column;
            .head{
                height: 200px;
                h4{
                    line-height: 40px;
                    color: orangered;
                    padding-left: 10px ;
                }
                img{
                    width: 100%;
                    height: 150px;
                }
            }
            .main{
                flex: 1;
                dl{
                    display: flex;
                    border-bottom: 1px solid #eeee;
                    margin: 10px;
                    dt{
                        flex: 1;
                        margin-right: 10px;
                    }
                    dd{
                        flex: 3;
                        span{
                            color: orangered;
                        }
                    }
                }
            }
        }
    }
    .active{
        color: orangered;
        background: #ccc;
    }
}
</style>